/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.insurance.cis.controllers;

import com.insurance.cis.daos.ChannelDao;
import com.insurance.cis.models.Channel;
import com.insurance.cis.scos.ChannelSearchCondition;
import com.insurance.cis.utils.MessageDialogUtils;
import com.insurance.cis.views.ChannelJDialogChooser;
import java.util.List;

/**
 *
 * @author TruongLQ
 */
public class ChannelChooserController {
    
    final ChannelJDialogChooser channelDialog;
    ChannelDao channelDao = new ChannelDao();
    
    public ChannelChooserController(javax.swing.JDialog channelDialog) {
        this.channelDialog = (ChannelJDialogChooser)channelDialog;
    }
    
    public boolean validateInputs() {
        if (!channelDialog.getTxtChannelID().getText().trim().isEmpty()) {
            try {
                Integer.parseInt(channelDialog.getTxtChannelID().getText().trim());
            } catch (NumberFormatException ex) {
                MessageDialogUtils.dialogError(channelDialog, "Channel ID must be numeric!");
                channelDialog.getTxtChannelID().requestFocus();
                return false;
            }
        }
        return true;
    }
    
    public List<Channel> searchChannels(String id, String desc) {
        return channelDao.getChannels(new ChannelSearchCondition(id, desc));
    }
}
